from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from math import *
import sys


class Clock(QWidget):
    def __init__(self):
        super().__init__()
        self.timer = QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(1000)

    def paintEvent(self, event):
        POINTS = [
            [QPoint(7, 8), QPoint(-7, 8), QPoint(0, -30)],
            [QPoint(7, 8), QPoint(-7, 8), QPoint(0, -65)],
            [QPoint(7, 8), QPoint(-7, 8), QPoint(0, -80)]
        ]
        
        COLORS = [
            QColor(200, 100, 0, 200),
            QColor(0, 127, 127, 150),
            QColor(0, 160, 230, 150)
        ]

        time = QTime.currentTime()
        TIME = [
            30*(time.hour() + time.minute() / 60),
            6*(time.minute() + time.second() / 60),
            6*time.second()
        ]

        side = min(self.width(), self.height())
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.translate(self.width()/2, self.height()/2)
        painter.scale(side / 200, side / 200)

        painter.save()
        for i in range(0, 60):
            if (i % 5) != 0:
                painter.setPen(COLORS[1])
                painter.drawLine(92, 0, 96, 0)
            else:
                painter.setPen(COLORS[0])
                painter.drawLine(88, 0, 96, 0)
            painter.rotate(360/60)
        painter.restore()

        painter.save()
        font = painter.font()
        font.setBold(True)
        painter.setFont(font)
        pointSize = font.pointSize()
        painter.setPen(COLORS[0])
        nhour = 0
        radius = 100
        for i in range(0, 12):
            nhour = i + 3
            if nhour > 12:
                nhour = nhour - 12

            x = radius*0.8*cos(i*30*pi/180.0) - pointSize
            y = radius*0.8*sin(i*30*pi/180.0) - pointSize/2.0
            width = pointSize*2
            height = pointSize
            painter.drawText(QRectF(x, y, width, height),
                                Qt.AlignCenter, str(nhour))
        painter.restore()

        # rotate for every second
        for i in range(3):
            painter.save()
            painter.setPen(Qt.NoPen)
            painter.setBrush(COLORS[i])
            painter.rotate(TIME[i])
            painter.drawConvexPolygon(QPolygonF(POINTS[i]))
            painter.restore()


if __name__ == "__main__":

    app = QApplication(sys.argv)
    form = Clock()
    form.show()
    app.exec_()
